package com.monkeygroup.mygoplus.common.DefinedView;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.monkeygroup.mygoplus.R;
import com.monkeygroup.mygoplus.common.utils.LocalInfo;


/**
 * 功能说明：提示框 作者：HuangSHIQUAN 创建日期：2016/4/18 21:30 所属项目：
 */
public class MyAlertDialog {

	private Activity activity;
	private String notice;
	private String bank;

 AlertDialog myDialog;
	 public MyAlertDialog(Activity activity,String notice,String bank){

	 this.activity=activity;
	 this.notice=notice;
	 this.bank=bank;

	 }

	/**
	 *
	 * @param activity
	 * @param notice
	 * @param type 1-不存在賬號 2-登錄次數提示 3-驗證碼錯誤提示
     */
	public  void show(Activity activity, String notice, int type) {

		myDialog = new AlertDialog.Builder(activity)
				.create();

		myDialog.show();

		myDialog.getWindow().setContentView(R.layout.mydialog);

		TextView txtNoticeO = (TextView) myDialog.getWindow().findViewById(
				R.id.txt_notice_one);
		TextView txtNoticeT = (TextView) myDialog.getWindow().findViewById(
				R.id.txt_notice_two);
		txtNoticeO.setText(notice);
		TextView txtNotice = (TextView) myDialog.getWindow().findViewById(
				R.id.txt_notice);

		TextView txtCount = (TextView) myDialog.getWindow().findViewById(
				R.id.txt_count);
		TextView myOk = (TextView) myDialog.getWindow().findViewById(
				R.id.my_ok);


		LinearLayout llOne = (LinearLayout) myDialog.getWindow().findViewById(
				R.id.ll_one);
		// 正确信息
		if (type == 1) {
			//imgNotice.setImageResource(R.drawable.pop_black_right);
			llOne.setGravity(Gravity.CENTER);
			txtNoticeO.setGravity(Gravity.CENTER);
			txtNoticeT.setVisibility(View.GONE);
		}
		else if(type == 2){
			llOne.setGravity(Gravity.CENTER);
			//imgNotice.setImageResource(R.drawable.pop_black_warning);
			txtCount.setVisibility(View.VISIBLE);

			String count = LocalInfo.getLoginCount(activity,bank);
			txtNoticeO.setGravity(Gravity.BOTTOM|Gravity.CENTER_VERTICAL);
			txtNoticeT.setGravity(Gravity.CENTER);
			txtCount.setGravity(Gravity.BOTTOM|Gravity.CENTER_VERTICAL);
			boolean flag =false;
			if("3".equals(count)){
				txtCount.setTextColor(activity.getResources().getColor(R.color.base_color));
				txtNoticeO.setText("密碼錯誤已超過 ");
				txtCount.setText(count+"次");
				flag=true;
			}
			else{
				txtNoticeO.setText("密碼錯誤 ");
				txtCount.setText(count+"次");
			}

			txtNotice.setVisibility(View.VISIBLE);
			txtNoticeT.setText("請重新輸入密碼");
			if(flag){

				txtNoticeO.setText("密碼錯誤已超過 ");
				txtCount.setText(count+"次");
				txtNoticeT.setText("進入簡訊驗證 發送新密碼");
				txtCount.setVisibility(View.VISIBLE);
			}

		}
		else if(type == 3){
			//imgNotice.setImageResource(R.drawable.pop_black_warning);
			txtNoticeO.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
			txtNoticeO.setText("臨時密碼有誤");
			txtNoticeT.setText("您輸入的臨時密碼有誤，請確認后再次輸入");
			myOk.setText("確認");
		}
		else{
			llOne.setGravity(Gravity.CENTER);
			txtNoticeO.setGravity(Gravity.CENTER);
			txtNoticeT.setVisibility(View.GONE);
		}

		myDialog.setCanceledOnTouchOutside(true);

		Handler mhandler = new Handler();
		mhandler.postDelayed(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				myDialog.dismiss();
				myDialog=null;
			}
		}, 5000);

		// .setOnClickListener(new View.OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// myDialog.dismiss();
		// }
		// });

		// return myDialog;

		//Toast.makeText(activity, notice, Toast.LENGTH_SHORT).show();
	}

}
